using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.HomeRefinancing
{
    public class RequireLoanDB
    {
        public RequireLoanDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public RequireLoan GetRequireLoan(Int64 HFID)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "[sprocHFLoanSelectSingleItem]";
            RequireLoan _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@HFID", HFID);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new RequireLoan();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }

        public Int64 Insert(RequireLoan requireloan)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocHFLoanInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
                _sPara.Add("@HFID", requireloan.HFID);
                _sPara.Add("@HFLoanPurpose", requireloan.HFLoanPurpose);
                _sPara.Add("@HFPropertyType",requireloan.HFPropertyType);
                _sPara.Add("@HFPropertyStatus",requireloan.HFPropertyStatus);
                _sPara.Add("@HFPropertyValue", requireloan.HFPropertValue);
                _sPara.Add("@HFAmount",requireloan.HFAmount);
                _sPara.Add("@HFLoanTenure",requireloan.HFLoanTenure);
                _sPara.Add("@HFInterestRateType", requireloan.HFInterestRateType);
                _sPara.Add("@HFLockInPeroid", requireloan.HFLockInPeroid);

                //Hide on 09/June/2010 - Sakthi
                //_sPara.Add("@HFName",requireloan.HFName);
                //_sPara.Add("@HFPhoneNo",requireloan.HFPhoneNo);
                //_sPara.Add("@HFEmailAddress", requireloan.HFEmailAddress);
                //_sPara.Add("@HFMortage",requireloan.HFMortage);
                //End

                _sPara.Add("@RefCEUserId", requireloan.RefCEUserId);
                _sPara.Add("@ViewedDetailId", requireloan.ViewedDetailId);
                _sPara.Add("@Status", requireloan.Status);
                _sPara.Add("@Info1", requireloan.Info1);
                _sPara.Add("@Info2", requireloan.Info2);
                _sPara.Add("@Info3", requireloan.Info3);
                _sPara.Add("@Info4", requireloan.Info4);
                _sPara.Add("@Info5", requireloan.Info5);
                _sPara.Add("@Info6", requireloan.Info6);
                _sPara.Add("@Info7", requireloan.Info7);
                _sPara.Add("@Info8", requireloan.Info8);
                _sPara.Add("@Info9", requireloan.Info9);
                _sPara.Add("@Info10", requireloan.Info10);
                _sPara.Add("@Info11", requireloan.Info11);
                _sPara.Add("@Info12", requireloan.Info12);
                _sPara.Add("@Info13", requireloan.Info13);
                _sPara.Add("@Info14", requireloan.Info14);
                _sPara.Add("@Info15", requireloan.Info15);
                _sPara.Add("@Info16", requireloan.Info16);
                _sPara.Add("@Info17", requireloan.Info17);
                _sPara.Add("@Info18", requireloan.Info18);
                _sPara.Add("@Info19", requireloan.Info19);
                _sPara.Add("@Info20", requireloan.Info20);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateRequest(RequireLoan requireloan)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocHFLoanRequestUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HFID", requireloan.HFID);
            _sPara.Add("@HFAmount", requireloan.HFAmount);
            _sPara.Add("@HFLoanTenure", requireloan.HFLoanTenure);
            _sPara.Add("@HFInterestRateType", requireloan.HFInterestRateType);
            _sPara.Add("@HFLockInPeroid", requireloan.HFLockInPeroid);
            _sPara.Add("@ViewedDetailId", requireloan.ViewedDetailId);
            _sPara.Add("@Status", requireloan.Status);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private RequireLoan FillDataRecord(DataTable myDataTable)
        {
            RequireLoan myRequireLoan = new RequireLoan();
            myRequireLoan.HFID = Convert.ToInt64(myDataTable.Rows[0]["HFID"].ToString());
            myRequireLoan.HFLoanPurpose = Convert.ToInt16(myDataTable.Rows[0]["HFLoanPurpose"].ToString());
            myRequireLoan.HFPropertyType = Convert.ToInt16(myDataTable.Rows[0]["HFPropertyType"].ToString());
            myRequireLoan.HFPropertyStatus = Convert.ToInt16(myDataTable.Rows[0]["HFPropertyStatus"].ToString());
            myRequireLoan.HFPropertValue = Convert.ToDouble(myDataTable.Rows[0]["HFPropertyValue"].ToString());
            myRequireLoan.HFAmount = Convert.ToDouble(myDataTable.Rows[0]["HFAmount"].ToString());
            myRequireLoan.HFLoanTenure = Convert.ToInt16(myDataTable.Rows[0]["HFLoanTenure"].ToString());
            myRequireLoan.HFInterestRateType = Convert.ToInt16(myDataTable.Rows[0]["HFInterestRateType"].ToString());
            myRequireLoan.HFLockInPeroid = Convert.ToInt16(myDataTable.Rows[0]["HFLockInPeroid"].ToString());

            //Hide on 09/June/2010 - Sakthi
            //myRequireLoan.HFName = myDataTable.Rows[0]["HFName"].ToString();
            //myRequireLoan.HFPhoneNo = myDataTable.Rows[0]["HFPhoneNo"].ToString();
            //myRequireLoan.HFEmailAddress = myDataTable.Rows[0]["HFEmailAddress"].ToString();
            //myRequireLoan.HFMortage = Convert.ToBoolean(myDataTable.Rows[0]["HFMortage"].ToString());
            //End

            myRequireLoan.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            myRequireLoan.CreatedDate = Convert.ToDateTime(myDataTable.Rows[0]["CreatedDate"].ToString());
            myRequireLoan.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[0]["ModifiedDate"].ToString());
            return myRequireLoan;
        }
        
    }
}